package org.dromara.system.controller.talent;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.TalentUserBo;
import org.dromara.system.domain.vo.TalentUserVo;
import org.dromara.system.service.ITalentUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 人才信息
 *
 * @author Lion Li
 * @date 2025-07-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/talent_user")
public class TalentUserController extends BaseController {

    private final ITalentUserService talentUserService;

    /**
     * 查询人才信息列表
     */
    @SaCheckPermission("talent:talent_user:list")
    @GetMapping("/list")
    public TableDataInfo<TalentUserVo> list(TalentUserBo bo, PageQuery pageQuery) {
        return talentUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出人才信息列表
     */
    @SaCheckPermission("talent:talent_user:export")
    @Log(title = "人才信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TalentUserBo bo, HttpServletResponse response) {
        List<TalentUserVo> list = talentUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "人才信息", TalentUserVo.class, response);
    }

    /**
     * 获取人才信息详细信息
     *
     * @param userId 主键
     */
    @SaCheckPermission("talent:talent_user:query")
    @GetMapping("/{userId}")
    public R<TalentUserVo> getInfo(@NotNull(message = "主键不能为空")
                                   @PathVariable Long userId) {
        return R.ok(talentUserService.queryById(userId));
    }

    /**
     * 新增人才信息
     */
    @SaCheckPermission("talent:talent_user:add")
    @Log(title = "人才信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TalentUserBo bo) {
        return toAjax(talentUserService.insertByBo(bo));
    }

    /**
     * 修改人才信息
     */
    @SaCheckPermission("talent:talent_user:edit")
    @Log(title = "人才信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TalentUserBo bo) {
        return toAjax(talentUserService.updateByBo(bo));
    }

    /**
     * 删除人才信息
     *
     * @param userIds 主键串
     */
    @SaCheckPermission("talent:talent_user:remove")
    @Log(title = "人才信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] userIds) {
        return toAjax(talentUserService.deleteWithValidByIds(List.of(userIds), true));
    }
}
